package com.epoch.servicecourse.controller;

import bean.vo.ResultInfo;

import com.epoch.servicecourse.service.ChapterService;
import exceptions.ParamsException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author mi
 */
@Slf4j
@RestController
public class ChapterController {
    @Resource
    private ChapterService chapterService;
    /**
     * 查询章节
     * @param courseId
     * @return ResultInfo
     */
    @GetMapping("epoch/stu/getChapterBy/{courseId}")
    public ResultInfo getChapterByCourse(@PathVariable("courseId") String courseId){
        ResultInfo resultinfo=new ResultInfo();
        try{
            resultinfo.setResult(chapterService.getChapterBy(courseId));
        }catch(ParamsException p){
            p.printStackTrace();
            resultinfo.setCode(p.getCode());
            resultinfo.setMsg(p.getMsg());
        }
        return resultinfo;
    }

    @GetMapping("epoch/stu/getPointBy/{courseId}/{chapterId}")
    public ResultInfo getPointByCourse(@PathVariable("courseId") String courseId,@PathVariable("chapterId") String chapterId){
        ResultInfo resultinfo=new ResultInfo();
        try{
            resultinfo.setResult(chapterService.getPointBy(courseId,chapterId));
        }catch(ParamsException p){
            p.printStackTrace();
            resultinfo.setCode(p.getCode());
            resultinfo.setMsg(p.getMsg());
        }
        return resultinfo;
    }
}
